// pages/selfManage/selfManage.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    username: "",
    userInfo: {},
    user: {}
  },
  onLoad: function () {
    let userInfo = wx.getStorageSync('userInfo');
    let user = wx.getStorageSync('user');
    // let userInfo = typeof wx.getStorageSync('userInfo') === 'string' ? JSON.parse(wx.getStorageSync('userInfo')) : wx.getStorageSync('userInfo');
    // let user = typeof wx.getStorageSync('user') === 'string' ? JSON.parse(wx.getStorageSync('user')) : wx.getStorageSync('user');
    let username = user.user_name;
    this.setData({
      username,
      user,
      userInfo
    })
  },
  //修改名字
  goEditName() {
    if (Object.keys(this.data.user).length == 0) {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      })
    } else {
      wx.navigateTo({
        url: '../../pages/editName/editName',
      })
    }
  },
  //修改支付密码
  goEditPass() {
    if (Object.keys(this.data.user).length == 0) {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      })
    } else if (this.data.user.safetyInfo.pay_password === null || this.data.user.safetyInfo.pay_password === '') {
      wx.showModal({
        content: '请先设置支付密码',
        showCancel: true,
        title: '提示',
        success: (result) => {
          if (result.confirm) {
            wx.navigateTo({
              url: '../../pages/setPass/setPass',
            })
          } else {
            wx.showToast({
              title: '已取消',
              icon: 'none'
            })
          }
        },
      })
    } else {
      wx.navigateTo({
        url: '../../pages/editPass/editPass',
      })
    }
  },
  logOut() {
    wx.clearStorage({
      success: (res) => {
        wx.switchTab({
          url: '../my/my',
        })
      },
    })

  }
})